#include "stdafx.h"
#include "VS2010CtxMenuFixApp.h"

static TCHAR g_szAppMutexName[] = __TEXT("VS2010CtxMenuFixApp:74ab1cb0-59f5-4192-9cc1-fb19fb54d921");

CAppMutex::CAppMutex()
{
    m_Success = FALSE;
    m_hAppMutex = NULL;

    Initialize();
}

CAppMutex::~CAppMutex()
{
    Cleanup();
}

void CAppMutex::Initialize()
{
    HANDLE hMutex = CreateMutex(NULL, TRUE, g_szAppMutexName);

    if (!hMutex)
    {
        return;
    }

    if (GetLastError() == ERROR_ALREADY_EXISTS)
    {
        CloseHandle(hMutex);
        return;
    }

    m_hAppMutex = hMutex;
    m_Success = TRUE;
}

void CAppMutex::Cleanup()
{
    if (m_hAppMutex)
    {
        CloseHandle(m_hAppMutex);
    }
}
